<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/7/15
 * Time: 下午2:18
 */

namespace App\Logic;
use App\Http\Model\Users As UserModel;

class UsersLogic extends BaseLogic
{
    protected $_users = null;

    public function __construct($users)
    {
        $this->_users = $users;
    }



    public static function getUserList($where,$page=15)
    {
        $builder = self::builder($where);
        $users = $builder->paginate($page);
        return new static($users);
    }


    private static function builder($where)
    {
        $builder = UserModel::query();

        $condition = [
            'created' => function ($param) use ($builder){
                $builder->where('created', '>', $param);
            },
        ];

        foreach ($where as $key => $value)
        {
            if (isset($condition[$key]))
            {
                $condition[$key]($value);
            }
        }
        return $builder;
    }

    public function getUsers()
    {
        return $this->_users;
    }
}